package org.balthie.demo.jdk.util.concurrent.future;

import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

// 增强Future功能，可以通过take方法获取到先执行完成的任务结果
//内部有一个先进先出的阻塞队列，用于保存已经执行完成的Future，通过调用它的take方法或poll方法可以获取到一个已经执行完成的Future

//原文链接：https://blog.csdn.net/li02112017/article/details/108310982
public class CompletionServiceDemo
{
    ExecutorCompletionService<Integer> service;
    
    public CompletionServiceDemo()
    {
        ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(5);
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        
        this.service = new ExecutorCompletionService<Integer>(executor);
    }

}
